#include "coroutine.h"
#include "glog/logging.h"
#include <iostream>

void func1(void *arg) {
  std::cout << "func1 " << std::endl;
  std::cout << "func1 " << std::endl;
  coroutine::Schedule::Instance()->Yield();
  std::cout << "func4 " << std::endl;
  std::cout << "func4 " << std::endl;
}
void func2(void *arg) {
  std::cout << "func2 " << std::endl;
  std::cout << "func2 " << std::endl;
  coroutine::Schedule::Instance()->Yield();
  std::cout << "func3 " << std::endl;
  std::cout << "func3 " << std::endl;
}
void test() {
  int t1 =
      coroutine::Schedule::Instance()->CreateCoroutine("func1", func1, nullptr);
  int t2 =
      coroutine::Schedule::Instance()->CreateCoroutine("func2", func2, nullptr);
  while (!coroutine::Schedule::Instance()->Finish()) {
    coroutine::Schedule::Instance()->Resume(t1);
    coroutine::Schedule::Instance()->Resume(t2);
  }
}
int main(int argc, char *argv[]) {
  FLAGS_alsologtostderr = 1;
  google::InitGoogleLogging(argv[0]);
  test();
  return 0;
}
